<?php

class Admin_TypestudyController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $typeStudys = new Application_Model_Dao_TypeStudy();
        $this->view->typeStudys = $typeStudys->getAll()->toArray();
    }

    public function addAction(){
    	
    	$form = new Application_Form_TypeStudy();
    	$form->appendValidationEngineFiles($this->view); 
    	$polish = BH_TranslatePL::getPolishTranslation();
  		$translate = new Zend_Translate('array', $polish, 'pl');
  		$form->setTranslator($translate);
    	
    	$form->submit->setLabel('Dodaj nowy rodzaj studiów');
		$this->view->TypeStudyForm = $form;
   	
    	$request = $this->getRequest();
    	if ($request->isPost()) {
    		if ($form->isValid($request->getPost())) {
    			$typeStudy = new Application_Model_Entities_TypeStudy();
    			$typeStudy->setDesignation( $form->getValue('designation'));
    			$typeStudyDao = new Application_Model_Dao_TypeStudy();
    			$typeStudyDao->saveTypeStudy($typeStudy);
    		
    			$this->_helper->redirector('index');		
    		}
    	}
    }
  
    
}